Skip to content

feat(content-gate): layout deletion and default content handling#4436

Merged
miguelpeixe merged 13 commits into
trunkfrom
feat/content-gate-default-layout
Feb 3, 2026
Merged

feat(content-gate): layout deletion and default content handling#4436
miguelpeixe merged 13 commits into
trunkfrom
feat/content-gate-default-layout

Conversation

@miguelpeixe
Copy link
Copy Markdown
Member

@miguelpeixe miguelpeixe commented Jan 30, 2026

All Submissions:

Changes proposed in this Pull Request:

Introduces default content handling and fallback strategies when retrieving the gate layout. For clarity, the gate content methods now receive a $gate_layout_id, even though it could be a np_gate_layout or a np_memberships_gate.

When creating a gate, layouts should now be created automatically. For the registration mode, it adds the contents of the "Registration Card" pattern:

image

For the custom access mode, it adds the generic paragraph:

image

Deleting a gate permanently should also delete its layouts.

Several new unit tests were added for:

  • creation of layouts upon gate creation
  • deletion of layouts upon gate deletion
  • gate content without a layout (should render default message)
  • gate layout content

How to test the changes in this Pull Request:

  1. Without our content gate strategy, make sure the Woo Memberships gate renders without any regression (both inline and overlay styles)
  2. Enable content gates (define( 'NEWSPACK_CONTENT_GATES', true );) and create a new gate with Registration Access
  3. Visit a post restricted by this new gate and confirm it renders the "Registration Card" pattern
  4. Confirm you can go through the gate flow
  5. Deactivate "Registration Access" and enable "Paid Access" (make sure to add a rule)
  6. Visit a restricted post and confirm you get the default message
  7. Edit each layout and confirm the changes persist and render in the gate
  8. Delete all layouts via CLI: wp post delete $(wp post list --post_type='np_gate_layout' --format=ids) --force
  9. Visit a restricted post and confirm the restriction is applied with a default message

Other information:

  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your changes, as applicable?
  • Have you successfully ran tests with your changes locally?

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR enhances the content gate feature by adding automatic layout deletion when gates are removed and implementing default content fallback handling when gate layouts don't exist.

Changes:

  • Adds automatic deletion of associated gate layouts when a gate is permanently deleted
  • Implements default content fallback when gate layout posts are deleted or don't exist
  • Creates default layouts automatically for registration and custom_access modes when creating new gates

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 8 comments.

File Description
includes/content-gate/trait-content-gate-layout.php Adds get_default_gate_content() method and updates get_inline_gate_content_for_post() and get_restricted_post_excerpt_for_gate() to handle missing gate layouts with default content fallback
includes/content-gate/class-content-gate.php Adds delete_gate_layouts() hook to clean up layouts on gate deletion, enhances create_gate() to automatically create default layouts, adds get_block_pattern_content() helper method, and updates create_gate_layout() to accept optional content parameter

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread includes/content-gate/class-content-gate.php Outdated
Comment thread includes/content-gate/class-content-gate.php
Comment thread includes/content-gate/class-content-gate.php
Comment thread includes/content-gate/class-content-gate.php
Comment thread includes/content-gate/trait-content-gate-layout.php Outdated
Comment thread includes/content-gate/class-content-gate.php
Comment thread includes/content-gate/trait-content-gate-layout.php Outdated
Comment thread includes/content-gate/class-content-gate.php Outdated
@miguelpeixe miguelpeixe marked this pull request as ready for review January 30, 2026 19:18
@miguelpeixe miguelpeixe requested a review from a team as a code owner January 30, 2026 19:18
@miguelpeixe miguelpeixe self-assigned this Jan 30, 2026
@miguelpeixe miguelpeixe added the [Status] Needs Review The issue or pull request needs to be reviewed label Jan 30, 2026
Copy link
Copy Markdown
Contributor

@dkoo dkoo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Working well! The only issue I found is that if creating a Registration gate layout for a gate that already exists (such as after deleting all gate layouts), it should be created with the same default Registration block pattern. I think we'd need to add that here.

@miguelpeixe
Copy link
Copy Markdown
Member Author

Thanks, @dkoo! Good catch, updated in 3a4a35b

@miguelpeixe miguelpeixe requested a review from dkoo February 3, 2026 13:40
@github-actions github-actions Bot added [Status] Approved The pull request has been reviewed and is ready to merge and removed [Status] Needs Review The issue or pull request needs to be reviewed labels Feb 3, 2026
@miguelpeixe miguelpeixe merged commit f0b3b18 into trunk Feb 3, 2026
8 checks passed
@miguelpeixe miguelpeixe deleted the feat/content-gate-default-layout branch February 3, 2026 16:57
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Feb 3, 2026

Hey @miguelpeixe, good job getting this PR merged! 🎉

Now, the needs-changelog label has been added to it.

Please check if this PR needs to be included in the "Upcoming Changes" and "Release Notes" doc. If it doesn't, simply remove the label.

If it does, please add an entry to our shared document, with screenshots and testing instructions if applicable, then remove the label.

Thank you! ❤️

matticbot pushed a commit that referenced this pull request Feb 5, 2026
# [6.31.0-alpha.1](v6.30.1...v6.31.0-alpha.1) (2026-02-05)

### Bug Fixes

* **collections:** hide indicator for unpublished collections ([#4434](#4434)) ([3eda622](3eda622))
* **content-gate:** persist restricted content ([#4420](#4420)) ([856695d](856695d))
* decrease image size for Collections in certain cases ([#4395](#4395)) ([de3c001](de3c001))
* **my-account:** "order again" checkout redirect ([#4427](#4427)) ([3a9e7fb](3a9e7fb))
* remove alignments from the My Account Block button ([#4438](#4438)) ([8de3526](8de3526))

### Features

* Add My Account button block ([#4409](#4409)) ([b0c414f](b0c414f))
* **avatar:** add custom byline support ([#4424](#4424)) ([152b1af](152b1af))
* **content-gate:** grouped access rules evaluation and normalization ([#4435](#4435)) ([aa182c9](aa182c9))
* **content-gate:** layout deletion and default content handling ([#4436](#4436)) ([f0b3b18](f0b3b18))
* **content-gate:** support group subscriptions access rule ([#4442](#4442)) ([416cd13](416cd13))
* **content-gate:** support new metering schema ([#4419](#4419)) ([e3f2f56](e3f2f56))
* **my-account:** new layout for single subscription pages ([#4425](#4425)) ([6425dbf](6425dbf)), closes [#4428](#4428) [#4432](#4432) [#4409](#4409) [#4419](#4419) [#4413](#4413) [#4434](#4434)
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Feb 5, 2026

🎉 This PR is included in version 6.31.0-alpha.1 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

matticbot pushed a commit that referenced this pull request Feb 10, 2026
# [6.32.0-alpha.1](v6.31.0...v6.32.0-alpha.1) (2026-02-10)

### Bug Fixes

* **collections:** hide indicator for unpublished collections ([#4434](#4434)) ([3eda622](3eda622))
* **content-gate:** persist restricted content ([#4420](#4420)) ([856695d](856695d))
* decrease image size for Collections in certain cases ([#4395](#4395)) ([de3c001](de3c001))
* **my-account:** "order again" checkout redirect ([#4427](#4427)) ([3a9e7fb](3a9e7fb))
* remove alignments from the My Account Block button ([#4438](#4438)) ([8de3526](8de3526))

### Features

* Add My Account button block ([#4409](#4409)) ([b0c414f](b0c414f))
* **avatar:** add custom byline support ([#4424](#4424)) ([152b1af](152b1af))
* **content-gate:** grouped access rules evaluation and normalization ([#4435](#4435)) ([aa182c9](aa182c9))
* **content-gate:** layout deletion and default content handling ([#4436](#4436)) ([f0b3b18](f0b3b18))
* **content-gate:** support group subscriptions access rule ([#4442](#4442)) ([416cd13](416cd13))
* **content-gate:** support new metering schema ([#4419](#4419)) ([e3f2f56](e3f2f56))
* **my-account:** new layout for single subscription pages ([#4425](#4425)) ([6425dbf](6425dbf)), closes [#4428](#4428) [#4432](#4432) [#4409](#4409) [#4419](#4419) [#4413](#4413) [#4434](#4434)
@github-actions
Copy link
Copy Markdown

🎉 This PR is included in version 6.32.0-alpha.1 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

matticbot pushed a commit that referenced this pull request Feb 16, 2026
# [6.32.0](v6.31.1...v6.32.0) (2026-02-16)

### Bug Fixes

* add check for my account before switching error notice ([#4484](#4484)) ([9e13eca](9e13eca))
* **collections:** hide indicator for unpublished collections ([#4434](#4434)) ([3eda622](3eda622))
* **content-gate:** persist restricted content ([#4420](#4420)) ([856695d](856695d))
* decrease image size for Collections in certain cases ([#4395](#4395)) ([de3c001](de3c001))
* **my-account:** "order again" checkout redirect ([#4427](#4427)) ([3a9e7fb](3a9e7fb))
* remove alignments from the My Account Block button ([#4438](#4438)) ([8de3526](8de3526))

### Features

* Add My Account button block ([#4409](#4409)) ([b0c414f](b0c414f))
* **avatar:** add custom byline support ([#4424](#4424)) ([152b1af](152b1af))
* **content-gate:** grouped access rules evaluation and normalization ([#4435](#4435)) ([aa182c9](aa182c9))
* **content-gate:** layout deletion and default content handling ([#4436](#4436)) ([f0b3b18](f0b3b18))
* **content-gate:** support group subscriptions access rule ([#4442](#4442)) ([416cd13](416cd13))
* **content-gate:** support new metering schema ([#4419](#4419)) ([e3f2f56](e3f2f56))
* **my-account:** new layout for single subscription pages ([#4425](#4425)) ([6425dbf](6425dbf)), closes [#4428](#4428) [#4432](#4432) [#4409](#4409) [#4419](#4419) [#4413](#4413) [#4434](#4434)
@github-actions
Copy link
Copy Markdown

🎉 This PR is included in version 6.32.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Status] Approved The pull request has been reviewed and is ready to merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants